#ifndef _DFS_CACHE
#define _DFS_CACHE

#include <string.h>
#include "dfs.h"

/* Definitions */
#define CMD_SIZE 100
#define UNIFIED_DIFF_CMD "diff -u "
#define APPEND ">"
#define SPACE " "
#define REPLICA_EXT ".tmp"
#define REPLICAS_FOLDER "/home/cache"
#define DIFF_FILE "mods.diff"
#define PATCH_CMD "patch"
#define DELETE_CMD "rm"

#define HASH_TAB_SIZE 10
#define CACHEKEY_COMPARATOR(el1, el2)    (strcmp(el1->key,el2->key))

/* Hash function definitions */
#define NHASH 29989
#define MULT 31

typedef struct CacheElement{
	struct CacheElement *next;
	struct CacheElement *previous;
	char key[NAME_MAX];
	char value[PATH_MAX];
	int hits;
	int miss_st;
	int mbit;	 /* Modified (Dirty) bit */
}CacheElement;

CacheElement *CacheTable[HASH_TAB_SIZE];

typedef struct CacheStats{
	int cache_sz;
	int fcells;
	int rcells;
}CacheStats;

/* Global variables*/
_PROTOTYPE( void init_cache, (void)							);
_PROTOTYPE( void destroy_cache, (void)						);
_PROTOTYPE( void insert_to_cache, (const char *,char *)		);
_PROTOTYPE( void update_cache_stats, (const char *)			);
_PROTOTYPE( int belongs_to_cache, (const char *,char *)		);

#endif
